<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>01-ref之字符串定义</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://static.web.sdo.com/chuanshi/common/react.development.js"></script>
    <script src="http://static.web.sdo.com/chuanshi/common/react-dom.development.js"></script>
    <script src="http://static.web.sdo.com/chuanshi/common/babel.min.js"></script>
    <script src="http://static.web.sdo.com/chuanshi/common/prop-types.js"></script>
</head>
<body>
    <div id="app" class="container" style="padding: 200px">

    </div>
</body>
</html>
<script type="text/babel">
    class App extends React.Component {
        state = {
            content: ""
        }
        getValue = () => {
            const { value } = this.refs.refInput;
            this.setState(state => ({
                content: value
            }))
        }
        render() {
            let Alert = this.state.content
                ? <div className="alert alert-danger">{this.state.content}</div>
                : null;
            return (
                <div className="form-group">
                    {Alert}
                    <input ref="refInput" className="form-control" type="text" />
                    <button onClick={this.getValue} className="mt-3 btn btn-primary">获取Input的值</button>
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById('app'))
</script>